# -*- coding: utf8 -*-
# $Id :  $



# Copyright 2008-2010, Pascal Fautrero & JCharles
#
# This file is part of PyArchiver.
# 
# PyArchiver is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PyArchiver is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PyArchiver.  If not, see <http://www.gnu.org/licenses/>.



# Import packages

import wx                        # This module uses the new wx namespace
import locale

_ = wx.GetTranslation            # Define _ or add _ to builtins in your app file

#---------------------------------------------------------------------------

class My_SearchCtrl(wx.SearchCtrl):
    def __init__(self, parent, frame, id=90, value="",
                 pos=wx.DefaultPosition, size=(270, -1), style=0):
        wx.SearchCtrl.__init__(self, parent, id, value,
                               pos, size, style=wx.TE_PROCESS_ENTER )
        
        #-------------------------------------------------------------------
        
        self.parent = frame
        
        #-------------------------------------------------------------------
        
        self.ShowSearchButton(True)
        self.ShowCancelButton(True)
        
        #-------------------------------------------------------------------
        
        self.SetMenu(self.on_menu())
        self.SetFocus()
        
        #-------------------------------------------------------------------

        # Display a tooltip
        if wx.Platform == "__WXMAC__":
            pass
        else:
            self.SetToolTipString(tip=_("Ctrl+Entry for tab."))

        #-------------------------------------------------------------------
        
        # Bind some events to an events handler
        self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.on_search_btn, self)
        self.Bind(wx.EVT_SEARCHCTRL_CANCEL_BTN, self.on_cancel_btn, self)
        self.Bind(wx.EVT_TEXT_ENTER, self.on_do_search)
        
    #-----------------------------------------------------------------------
    
    def on_do_search(self, event):
        self.parent.FilterSupports(event.GetString())
        self.parent.SelectedSupport = ""
        self.parent.SelectedFolder = event.GetString()		
     
     
    def on_search_btn(self, event):
        pass
     
     
    def on_cancel_btn(self, event):
        self.Clear()
     
     
    def on_menu(self):
        self.menu = wx.Menu()
        item = self.menu.Append(-1, text=_("Prefixes folders :"))
        item.Enable(False)
       # self.menu.AppendSeparator()
        
        i=0		
        for txt in [ "10109_",
                     "10609_",
                     "10809_",
                     "10110_",
                     "10610_",
                     "10810_" ]:
            item = self.menu.AppendRadioItem(i, txt)
            self.Bind(wx.EVT_MENU, self.on_click_menu, item)            
            i+=1		
        return self.menu


    def on_click_menu(self, event):
        searchMenu = self.GetMenu().GetMenuItems()
        self.SetValue(searchMenu[event.GetId()+1].GetLabel())


